package com.example.whopxx.utils;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCUtils {
    public static Connection getConnection() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/java_web_db?useSSL=false&characterEncoding=UTF-8&userSSL&serverTimezone=GMT%2B8";
        String username = "root";
        String password = "Wu031026";
        Connection connection = DriverManager.getConnection(url, username, password);
        return connection;
    }
    // 关闭
    public static void release(Statement statement, Connection connection){
        if(statement != null){
            try{
                statement.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
            statement = null;
        }
        if(connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            connection = null;
        }
    }


}
